package com.victualler.core.common.dto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Aouthor Guoshichang
 * @Date 14:03 on 2018/5/28.
 * @Function 查询的hql拼装结果对象
 */
public class SimpleQueryObjectVO {
       //hql语句中的select中的条件
    private StringBuffer selectString;
    //hql语句中的form中的条件
    private StringBuffer fromString;
    //hql语句中的where中的条件
    private StringBuffer whereString;
    //hql语句中的groupBy中的条件
    private StringBuffer groupByString;
    //hql语句中的orderBy中的条件
    private StringBuffer orderByString;
    //where条件中值的map
    private Map<String,Object> whereValueMap;
    //查询结果的字段映射
    private List selectField;

    private int pageNo = -1;
    private int limit = -1;
    /**
     * @Aouthor Guoshichang
     * @Date 14:13 on 2018/5/28.
     * @Function bean初始化
     */
    public SimpleQueryObjectVO() {
        selectString = new StringBuffer();
        fromString = new StringBuffer();
        whereString = new StringBuffer();
        groupByString = new StringBuffer();
        orderByString = new StringBuffer();
        whereValueMap = new HashMap<>();
        selectField = new ArrayList<>();
    }

    public String toSql(){
        return new StringBuffer().append(selectString).append(" ").append(fromString).append(" ").append(whereString).append(" ").append(groupByString).append(" ")
               .append(orderByString).toString();
    }
    public String toCountSql(){
        StringBuffer count= new StringBuffer("select count(*) from (") .append(this.toSql()) .append(") temp ");
        return count.toString();
    }

    public StringBuffer getSelectString() {
        return selectString;
    }

    public void setSelectString(StringBuffer selectString) {
        this.selectString = selectString;
    }

    public StringBuffer getFromString() {
        return fromString;
    }

    public void setFromString(StringBuffer fromString) {
        this.fromString = fromString;
    }

    public StringBuffer getWhereString() {
        return whereString;
    }

    public void setWhereString(StringBuffer whereString) {
        this.whereString = whereString;
    }

    public StringBuffer getGroupByString() {
        return groupByString;
    }

    public void setGroupByString(StringBuffer groupByString) {
        this.groupByString = groupByString;
    }

    public StringBuffer getOrderByString() {
        return orderByString;
    }

    public void setOrderByString(StringBuffer orderByString) {
        this.orderByString = orderByString;
    }

    public Map<String, Object> getWhereValueMap() {
        return whereValueMap;
    }

    public void setWhereValueMap(Map<String, Object> whereValueMap) {
        this.whereValueMap = whereValueMap;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public List getSelectField() {
        return selectField;
    }

    public void setSelectField(List selectField) {
        this.selectField = selectField;
    }
}
